package org.example.guide.persistence;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.guide.domain.RealtimeInfo;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface realtimeInfoMapper {
    @Select("select realtimeinfo.id,GuideID,Name,VisitorCount,Location,Timestamp from realtimeinfo,guidemsg where realtimeinfo.GuideID=guidemsg.id")
    List<RealtimeInfo> selectAll();

    @Select("select realtimeinfo.id,GuideID,Name,VisitorCount,Location,Timestamp from realtimeinfo,guidemsg where realtimeinfo.GuideID=guidemsg.id and guidemsg.name LIKE CONCAT('%', #{name}, '%')")
    List<RealtimeInfo> selectByName(String name);

    @Select("select realtimeinfo.id,GuideID,Name,VisitorCount,Location,Timestamp from realtimeinfo,guidemsg where realtimeinfo.GuideID=guidemsg.id and realtimeinfo.GuideID = #{guideID} ")
    RealtimeInfo selectByID(int guideID);

    @Insert("INSERT INTO realtimeinfo (id,GuideID,VisitorCount,Location,Timestamp) VALUES (#{id},#{GuideID},#{VisitorCount},#{Location},#{Timestamp})")
    int insert(int id,int GuideID, int VisitorCount, String Location, String Timestamp);

    @Delete("DELETE FROM realtimeinfo WHERE GuideID=#{id}")
    void delete(int id);
}

